﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FSS.Core.Controls;
using Ext.Net;
using FSS.BLL.Entities;
using FSS.BLL.Services;
using FSS.Core.Util;
using System.Web.Security;

namespace SalesManagement
{
    public partial class Login : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnLogin_Click(object sender, DirectEventArgs e)
        {
            string userName = txtUsername.Text.Trim();
            string password = txtPassword.Text.Trim();
            bool remember = chkRemeber.Checked;
            UserEntity userEntity = new UserEntity();
            userEntity.UserName = userName;
            UserService userService = UserService.GetInstance();
            userEntity = userService.LoadByPrimaryKey(userEntity);
            if (null != userEntity)
            {
                if (null != userEntity || string.Empty != userEntity.UserName)
                {
                    string encrypPassword = Encryption.StringToMD5Hash(password);
                    if (encrypPassword.Equals(userEntity.Password))
                    {
                        string returnUrl = Request.QueryString["ReturnUrl"];
                        FormsAuthentication.RedirectFromLoginPage(userName, remember);
                        if (returnUrl == null) returnUrl = "~/Default.aspx";
                        Response.Redirect(returnUrl);
                        return;
                    }
                }

            }
            lblError.Text = "Đăng nhập không thành công";
            lblError.Show();
        }

    }
}
